package com.aw.baselib.widgets.font

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.text.SpannableString
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import android.util.AttributeSet
import com.aw.baselib.base.AwBaseApplication

/**
 * @author : hzw
 */
@SuppressLint("AppCompatCustomView")
class AwTvMediumRed(context: Context, attrs: AttributeSet?) : AwTvRegularBase(context, attrs) {
    override fun setViewBg() {}

    init {
        typeface = AwBaseApplication.instance?.typefaceMedium
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
    }

    override fun setText(text: CharSequence, type: BufferType) {
        if (text != null && text.length >= 1) {
            val ss = SpannableString(text)
            ss.setSpan(
                ForegroundColorSpan(Color.RED), text.length - 1, text.length,
                Spanned.SPAN_INCLUSIVE_INCLUSIVE
            )
            super.setText(ss, type)
        } else {
            super.setText(text, type)
        }
    }
}